﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Elementum
{
    class Stage1_1 : Stage
    {


        public Stage1_1(Game game) : base(game) { }

        DateTime dateTime = DateTime.Now;
        float GROUND_ALPHA = 0f;

        public override void InitializeScenes()
        {
            base.InitializeScenes();

            Animation title = new Animation("images/title/stageTitle", new Rectangle(2, 328, 134, 38), new Point(134, 38));
            title.Scale = 1.2f;
            Transition tra = new DefauldTransition(1, 0, 0, 60);
            tra.Register(this);
            tra = new TitleTransition(title, new Vector2(430, 150), 0, 1, 80, 220);//460, 391
            tra.Register(this);

            for (int i = 0; i < 4; i++)
            {
                Animation a = new Animation("images/stages/stage1/m" + i);
                a.LayerDepth = 0.9f;
                _backGround.Add(a);
            }
            _backGroundPos = new Vector2(-600, -400);


            for (int i = 0; i < 3; i++)
            {
                Animation wallBack = new Animation("images/stages/stage1.1/stage1.1_" + i);
                //wallBack.LayerDepth = 0.9f;
                _wallBackGround.Add(wallBack);
            }
            _wallBackGroungPos = new Vector2(-250, 62);


            //_scenceBound = new Rectangle((int)(basePos.X + 380), (int)(basePos.Y + 480),
            //       1024 * (_backGround.Count() - 1) + _backGround[_backGround.Count() - 1]._frameSize.X - 770,
            //      _backGround[0]._frameSize.Y - 620);
            _scenceBound = new Rectangle(100, 20,
                   1780,
                  350);

            
            
            camera.Bound = _scenceBound;
            camera.CameraTransfer = 50;
            GroundObject grount =
            StateFactory.CreateGround(this, 270, 445, 512, 50, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreateGround(this, -101, 319, 230, 303, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreatekillBund(this, 558, 475, 64, 64, 0); grount.CurrentAnimation = new Animation("images/ground/thorn", new Point(64, 64));
            grount =
            StateFactory.CreateGround(this, 676, 445, 172, 50, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreatekillBund(this, 810, 475, 96, 64, 0); grount.CurrentAnimation = new Animation("images/ground/thorn", new Point(96, 64));
            grount =
            StateFactory.CreateGround(this, 897, 445, 78, 50, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreatekillBund(this, 1001, 475, 128, 64, 0); grount.CurrentAnimation = new Animation("images/ground/thorn", new Point(128, 64));
            grount =
            StateFactory.CreateGround(this, 1691, 445, 596, 50, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreateGround(this, 1149, 445, 167, 50, 0f); grount.Alpha = GROUND_ALPHA;
            grount =
            StateFactory.CreatekillBund(this, 1313, 479, 160, 64, 0); grount.CurrentAnimation = new Animation("images/ground/thorn", new Point(160, 64));
            grount =
            StateFactory.CreateGround(this, 1772, 250, 439, 50, 0f); grount.Alpha = GROUND_ALPHA;
            Floor floor;
            if (12 < dateTime.Hour && 16 > dateTime.Hour)
            {
                floor = StateFactory.CreateFloor(this, 1608, 300, 40, 166, 0, 0, 10, 0, 10);
                floor.CurrentAnimation = new Animation("images/items/vine", new Point(40, 180));
            }
            StateFactory.CreatePortal("Stage1_1_Portal_3", this, 1882, 370, "stage2", "Stage2_Protal_1");

            StateFactory.CreatePortal("Stage1_1_Portal_2", this, 1882, 175, "stage2", "Stage2_Protal_3");
            grount =
            StateFactory.CreateGround(this, 2169, 291, 359, 358, 0f); grount.Alpha = GROUND_ALPHA;
            StateFactory.CreatePortal("Stage1_1_Portal_1", this, 192, 370, "stage1", "Stage1_Protal_1");


            Font = ResourceManager.LoadSpriteFont("SpriteFont1");
            MusicManager.AddMusic("Music/doorlock", "doorlock", 0.001f, false);

            _song = MusicManager.LoadSong("Music/stageroot");

            if (GameClass._musicString == "Music/stageroot")
            { }
            else
            {
                GameClass._musicString = "Music/stageroot";
                MediaPlayer.Play(_song);
            }
            MediaPlayer.IsRepeating = true;
           // MediaPlayer.Volume = 1f;

            _startProtal = new ProtalCommand("stage1_1", "Stage1_1_Portal_1");

        }


        public override void OnDraw(SpriteBatch spriteBatch, int delta)
        {
            base.OnDraw(spriteBatch, delta);
            //GraphicsDevice.Clear(Color.White);


            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);

            foreach (VisibleObject b in actors)
                b.OnDraw(spriteBatch, camera.Transform);

            spriteBatch.End();

            //spriteBatch.Begin();
            //spriteBatch.DrawString(Font, "" + dateTime.Hour, new Vector2(50, 50), Color.Black);
            // spriteBatch.End();

        }

        public override void Update(int delta)
        {
            base.Update(delta);

            //a.Update(delta);
            //mic.Update();
            // MusicManager.FadeInMusic("first");


        }

        public override Stage Clone()
        {
            Stage1_1 stage = new Stage1_1(Game);
            stage.InitializeScenes();
            return stage;
        }

        public override void Dispose()
        {
            //mic.Dispose();
            base.Dispose();
            //mic.Dispose();
        }
    }
}
